package day12.console.impl;

import day12.console.ConsoleCommand;
import day12.packet.request.GroupMessageRequestPacket;
import day12.util.IDUtil;
import day12.util.session.SessionUtil;
import io.netty.channel.Channel;

import java.util.Scanner;

/**
 * @author chenshijie
 * @date 2024/1/3 10:26
 */

public class GroupMessageConsoleCommand implements ConsoleCommand {
    @Override
    public void exec(Scanner sc, Channel channel) {
        GroupMessageRequestPacket groupMessageRequestPacket = new GroupMessageRequestPacket();

        System.out.println("请输入想发送消息的群聊群号");
        String groupIdVal = sc.nextLine();
        if (IDUtil.isNumeric(groupIdVal)) {
            int groupId = Integer.parseInt(groupIdVal);
            System.out.println("请输入想发送的消息");
            String groupMessage = sc.nextLine();
            groupMessageRequestPacket.setGroupId(groupId);
            groupMessageRequestPacket.setGroupMessage(groupMessage);
            groupMessageRequestPacket.setFromUser(SessionUtil.getSession(channel));
            channel.writeAndFlush(groupMessageRequestPacket);
        } else {
            System.out.println("群号输入格式不正确，请输入9位数字");
        }
    }
}
